//
//  WorkManager.swift
//  WorkTime
//
//  Created by XiangYe on 2017/6/26.
//  Copyright © 2017年 XiangYe. All rights reserved.
//

import UIKit

let timeKey = "timeKey"

class WorkManager: NSObject {

    //管理类:单例模式
    private static let instance: WorkManager = WorkManager()
    
    private override init() {
        
    }
    
    static var shared: WorkManager {
    
        return self.instance
    }
    
    //获取当前时间
    func getCurrentTime() -> String {
        
        var timeStr: String = ""
        
        if let tempStr = UserDefaults.standard.object(forKey: timeKey) {
            
            timeStr = tempStr as! String
            
        } else {
        
        let currentTime = NSDate()
        
        let dateFormatter = DateFormatter()

        dateFormatter.dateFormat = "HH:mm:ss"
            
        timeStr = dateFormatter.string(from: currentTime as Date)
            
        UserDefaults.standard.set(timeStr, forKey: timeKey)
            
        }
        
        return timeStr
    }
    
    func removeHistory() {
        
        UserDefaults.standard.removeObject(forKey: timeKey)
    }
    
}
